package com.aoyy.action;

import java.util.Set;
import java.util.HashSet;
import java.util.Map;
import com.opensymphony.xwork2.ActionSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.apache.struts2.interceptor.RequestAware;
import org.apache.struts2.interceptor.SessionAware;
import org.apache.struts2.interceptor.ApplicationAware;
import com.aoyy.model.User;
import com.aoyy.model.OrderItem;
import com.aoyy.dao.IUploadFileDao;
import com.aoyy.dao.IUserDao;
import com.aoyy.dao.IOrderDao;
import com.aoyy.dao.IProductTypeDao;
import com.aoyy.dao.IProductDao;
/**=======================================================================
 * <code>BaseAction</code> class for base action
 * @author Administrator
 * @date 2017-07-13
 * ======================================================================== */
public class BaseAction extends ActionSupport implements RequestAware, SessionAware, ApplicationAware {
    private static final long serialVersionUID = -479756496344935577L;
  @Autowired
  protected IUserDao userDao;
  @Autowired
  protected IProductTypeDao productTypeDao;
  @Autowired
  protected IProductDao productDao;
  @Autowired
  protected IOrderDao orderDao;
  @Autowired
  protected IUploadFileDao uploadFileDao;
  
  protected Map<String, Object> request;
  protected Map<String, Object> session;
  protected Map<String, Object> application;
  
  protected Integer id;
  protected Integer[] ids;
  protected Integer pageNo = 1;
  protected Integer pageSize = 10;
  
  public static final String INDEX = "index";
  public static final String LOGIN = "login";
  public static final String LOGOUT = "logout";
  public static final String REGISTER = "register";
  public static final String MANAGER = "manager";
  public static final String LIST = "list";
  public static final String EDIT = "edit";
  public static final String UPDATE = "update";
  public static final String ADD = "add";
  public static final String SELECT = "select";
  public static final String QUERY = "query";
  
  public User getLoginUser() {
	return session.get("user") == null ? null : (User) session.get("user");  
  }
  
  @SuppressWarnings("unchecked")
  protected Set<OrderItem> getCart() {
    return session.get("cart") == null ? new HashSet<OrderItem>() : (Set<OrderItem>) session.get("cart");
  }
  
  @Override
  public void setApplication(Map<String, Object> request) {
	this.request = request;
  }

  @Override
  public void setSession(Map<String, Object> session) {
	this.session = session;
  }
  
  @Override
  public void setRequest(Map<String, Object> application) {
	this.application = application;
  }
  
  public void setId(Integer id) {
	this.id = id;  
  }
  public Integer getId() {
	return id;  
  }
  
  public void setIds(Integer[] ids) {
	this.ids = ids;  
  }
  public Integer[] getIds() {
	return ids;  
  }
  
  public void setPageNo(Integer pageNo) {
    this.pageNo = pageNo;	  
  }
  public Integer getPageNo() {
	return pageNo;  
  }
  
  public void setPageSize(Integer pageSize) {
	this.pageSize = pageSize; 
  }
  public Integer getPageSize() {
	return pageSize;  
  }
  
  public String index() {
    return INDEX; 
  }
  
  public String login() {
	return LOGIN;  
  }
  
  public String logout() {
	return LOGOUT;  
  }
  
  public String register() {
	return REGISTER;  
  }
  
  public String manager() {
	return MANAGER;  
  }
  
  public String list() {
	return LIST;  
  }
  
  public String edit() {
	return EDIT;  
  }
  
  public String update() {
	return UPDATE;  
  }
  public String add() {
	return ADD;  
  }
  
  public String select() {
	return SELECT;  
  }
  
  public String query() {
	return QUERY;  
  }
   
  public String execute() {
	return SUCCESS;  
  }

}